
# import pymysql
# from pymysql.cursors import DictCursor
#
# with pymysql.Connect(
#     host="127.0.0.1",
#     user="root",
#     password="123456",
#     database="walkertest",
#     cursorclass=DictCursor
# ) as connect:
#     cursor = connect.cursor()  # 获取游标，通过游标来执行sql
#     # 执行sql语句
#     sql = "select id, name, app from django_migrations;"
#     cursor.execute(sql)  # 执行sql
#
#     # 获取查询结果
#     # cursor.fetchone()获取一条数据，游标移动，再次获取时获取下一条
#     # print(cursor.fetchone())
#     # print(cursor.fetchone())
#     # print(cursor.fetchone())
#     # print(cursor.fetchone())
#     # print(cursor.fetchone())
#
#     # cursor.fetchall()获取从游标开始到最后的所有数据
#     # print(cursor.fetchall())
#
#     for data in cursor.fetchall():
#         print(data['name'])

import pymysql
from pymysql.cursors import DictCursor

with pymysql.Connect(
    host="127.0.0.1",
    user="root",
    password="123456",
    database="walkertest",
    cursorclass=DictCursor
) as connect:
    cursor = connect.cursor()  # 获取游标，通过游标来执行sql
    # 执行sql语句
    sql = "insert into xxx () value()"
    cursor.execute(sql)

    connect.commit()  # 操作类的sql，使用游标执行后，必须要用connect.commit进行提交，才能够保存到数据库中